﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Common.Enums;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Client.Interface;

namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class frmEmployeeAdd : FormBase
    {
        public frmEmployeeAdd()
        {
            InitializeComponent();
        }

        public DBEntityEmployee employeeInfo
        {
            set
            {
                employeeInfoControl.EmployeeInfo = value;
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            string error = string.Empty;
            DBEntityEmployee employeeInfo;
            if(!employeeInfoControl.CheckInput(out error, out employeeInfo)){
                MsgBox.MsgInfo(error);
                return;
            }

            bool bState = false;
            if (employeeInfoControl.EmployeeInfo == null)
            {
                //新增
                bState = BussinessProxyManager.Instance.InsertEmployee(employeeInfo, out error);
            }
            else
            {
                //修改
                employeeInfo.EMPLOYEEID = employeeInfoControl.EmployeeInfo.EMPLOYEEID;
                bState = BussinessProxyManager.Instance.UpdateEmployee(employeeInfo, out error);
            }
            if (bState == false)
            {
                MsgBox.MsgInfo("保存员工信息错误：" + error);
            }
            else
            {
                MsgBox.MsgInfo("保存成功。");
                this.DialogResult = DialogResult.OK;
            }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (MsgBox.MsgQue("是否要退出？"))
            {
                this.DialogResult = DialogResult.Cancel;
            }
        }
    }
}
